package com.doudou.provider.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;

/**
 * @Author: 傻男人
 * @Date: 2020/5/25 11:28
 * @Version: 1.0
 * @Description:
 */
@Slf4j
@Configuration
@EnableResourceServer
@EnableWebSecurity
public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {

    private static final String DEMO_RESOURCE_ID = "app_client";

    /**
     * 以代码形式配置资源服务器id，配置文件配置不生效
     * @param resources
     */
//    @Override
//    public void configure(ResourceServerSecurityConfigurer resources){
//        resources.resourceId(DEMO_RESOURCE_ID).stateless(true);
//    }

    @Override
    public void configure(HttpSecurity http) throws Exception {

//        http.authorizeRequests().antMatchers("/test**","/manager**").permitAll().anyRequest().authenticated().and().csrf().disable();
        http.authorizeRequests().antMatchers("/test**","/manager**","/basic**").permitAll()
                .antMatchers("/order**")
                .hasRole("SYS").and().httpBasic().and()
                .antMatcher("/**")
                .authorizeRequests().anyRequest().authenticated();
    }

}
